<?php

/**
 * This is the model class for table "penerimaan_tamu".
 *
 * The followings are the available columns in table 'penerimaan_tamu':
 * @property integer $id_penerimaan_tamu
 * @property string $jadwal_mulai
 * @property string $jadwal_selesai
 * @property string $status_terima
 * @property string $no_konfirmasi
 * @property string $jumlah_tamu
 * @property string $id_tamu
 * @property string $id_pegawai
 * @property string $id_keperluan
 * @property string $id_meetingroom
 * @property string $id_kartu_tamu
 * @property integer $janji
 * @property string $lama_tunggu
 * @property string $aktual_mulai
 * @property string $aktual_selesai
 * @property string $jam_datang
 * @property string $tanggal
 * @property integer$id_kartu_tamu
 * @property string $status_terima
 *
 * The followings are the available model relations:
 * @property MstJenisKeperluan $idKeperluan
 * @property MstKartuTamu $idKartuTamu
 * @property MstMeetingroom $idMeetingroom
 * @property MstPegawai $idPegawai
 * @property MstTamu $idTamu
 */
class PenerimaanTamu extends CActiveRecord
{
        /**
         * @var String[] 
         */
        private static $_statusPenerimaan = array(
              '0' => 'Menunggu',
              '1' => 'Checkin',
              '2' => 'Checkout',
              '3' => 'Ditolak',
              '4' => 'Reschedule'
            );
        
        /**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PenerimaanTamu the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'penerimaan_tamu';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('status_terima, jumlah_tamu, id_tamu, id_pegawai, id_keperluan, tanggal, id_kartu_tamu', 'required'),
			array('janji', 'numerical', 'integerOnly'=>true),
			array('status_terima', 'length', 'max'=>200),
			array('no_konfirmasi', 'length', 'max'=>5),
			array('jumlah_tamu', 'length', 'max'=>45),
			array('id_tamu, id_pegawai, id_keperluan, id_meetingroom, id_kartu_tamu', 'length', 'max'=>20),
			array('jadwal_mulai, jadwal_selesai, lama_tunggu, aktual_mulai, aktual_selesai, jam_datang', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_penerimaan_tamu, jadwal_mulai, jadwal_selesai, status_terima, no_konfirmasi, jumlah_tamu, id_tamu, id_pegawai, id_keperluan, id_meetingroom, id_kartu_tamu, janji, lama_tunggu, aktual_mulai, aktual_selesai, jam_datang, tanggal', 'safe', 'on'=>'search'),
		);
	}
        
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'Kegiatan' => array(self::BELONGS_TO, 'JenisKegiatan', 'id_kegiatan'),
			'Keperluan' => array(self::BELONGS_TO, 'JenisKeperluan', 'id_keperluan'),
			'Meetingroom' => array(self::BELONGS_TO, 'Meetingroom', 'id_meetingroom'),
			'KartuTamu' => array(self::BELONGS_TO, 'KartuTamu', 'id_kartu_tamu'),
			'Pegawai' => array(self::BELONGS_TO, 'Pegawai', 'id_pegawai'),
			'Tamu' => array(self::BELONGS_TO, 'Tamu', 'id_tamu'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_penerimaan_tamu' => 'Id Penerimaan Tamu',
			'jadwal_mulai' => 'Jadwal Mulai',
			'jadwal_selesai' => 'Jadwal Selesai',
			'status_terima' => 'Status Terima',
			'no_konfirmasi' => 'No Konfirmasi',
			'jumlah_tamu' => 'Jumlah Tamu',
			'id_tamu' => 'Id Tamu',
			'id_pegawai' => 'Id Pegawai',
			'id_keperluan' => 'Id Keperluan',
			'id_meetingroom' => 'Id Meetingroom',
			'id_kartu_tamu' => 'Id Kartu Tamu',
			'janji' => 'Janji',
			'lama_tunggu' => 'Lama Tunggu',
			'aktual_mulai' => 'Aktual Mulai',
			'aktual_selesai' => 'Aktual Selesai',
			'jam_datang' => 'Jam Datang',
			'tanggal' => 'Tanggal',
		);
	}

 
        
        public static function statusPenerimaan($key=null)
        {
            return self::$_statusPenerimaan[$key];
        }
        
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search($id_pegawai=null)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_penerimaan_tamu',$this->id_penerimaan_tamu);
		$criteria->compare('jadwal_mulai',$this->jadwal_mulai,true);
		$criteria->compare('jadwal_selesai',$this->jadwal_selesai,true);
		$criteria->compare('status_terima',$this->status_terima,true);
		$criteria->compare('no_konfirmasi',$this->no_konfirmasi,true);
		$criteria->compare('jumlah_tamu',$this->jumlah_tamu,true);
		$criteria->compare('id_tamu',$this->id_tamu,true);
		$criteria->compare('id_pegawai',$this->id_pegawai,true);
		$criteria->compare('id_keperluan',$this->id_keperluan,true);
		$criteria->compare('id_meetingroom',$this->id_meetingroom,true);
		$criteria->compare('id_kartu_tamu',$this->id_kartu_tamu,true);
		$criteria->compare('janji',$this->janji);
		$criteria->compare('lama_tunggu',$this->lama_tunggu,true);
		$criteria->compare('aktual_mulai',$this->aktual_mulai,true);
		$criteria->compare('aktual_selesai',$this->aktual_selesai,true);
		$criteria->compare('jam_datang',$this->jam_datang,true);
                
                if($this->tanggal!='')
                    $criteria->compare('tanggal', date('Y-m-d', strtotime($this->tanggal)), false);
                else
                    $criteria->compare('tanggal', date('Y-m-d'), false);
                
                
                $criteria->order = 'id_penerimaan_tamu DESC, tanggal DESC';
                
                if($id_pegawai!=NULL)
                    $criteria->compare('id_pegawai', $id_pegawai, false);
                
                //$criteria->compare('status_terima', 'menunggu', true);
                $criteria->compare('status_terima', 'checkin', true, 'OR');
                
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}